package com.example.kafka_and_sb.service;

import com.example.kafka_and_sb.tool.RedisUtil;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;


//kafka-topics.bat --zookeeper localhost:2181 --create --topic topic1 --replication-factor 1 --partitions 4
@Component
public class MyConsumer {

    @Resource
    RedisUtil redisUtil;

    @KafkaListener(topics = "topic1")
    public void listen(ConsumerRecord<?,String> record) {
        String value = record.value();
        System.out.println(value);
        redisUtil.set("kafka",value);
        System.out.println(record);
    }
}
